import pagination from '@/views/pagination'  //分页组件
import agentHttp from '@/utils/agentHttp.js'
import {debounce,timestampToTime,initDataTime} from '@/utils/index.js'
import PostponeBill from './Edit/PostponeBill' ;//延期组件  
import AddGathering from './Edit/AddGathering' ;//添加回款信息组件  
import GatheringDetail from './Edit/GatheringDetail' ;//回款详情列表组件  



export default {
  name: 'priceAudit',
  created(){
     this.seachData();
     this.getStatusMap();
  },
  components:{pagination,PostponeBill,AddGathering,GatheringDetail},
  data() {
  	return {
      //搜索字段
  		searchForm:{
  			    dealerName:"",
            orderNumber:"",
            startDate:"",
            endDate:"",
            carOrderStatus:'',    //订单状态
            isSettle:'',          //第一期服务费状态
            isDelay:'',           //是否延期
      },
      //表格字段
      tableData: [],
      id:'',            //穿给子组件的id
      carOrderId:null,  //传递给子组件的id
      isSettle:null,     //第一期服务费
      isDelay:null,     //是否延期
      carOrderStatus:null,     //订单状态
      statusMap:'',
      //发送给弹窗的数据
      dialogSendData:{
        isAdd:true,                //是否为编辑或者新增  true是   false否
        dialogFormVisible:false,   //弹窗是否显示        true是   false否
        id:""          //请求参数            自定义 例如index或者id
      },
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now() 
        }
      },
      endDateOpt:{
        disabledDate:(time)=>{
          return  time.getTime()< new Date(this.searchForm.startDate).getTime();
        }
      },
      resetFormStatus:false,
      childCode:null,
      
  	}
  },

  methods: {
    seachData(){
      if(!this.resetFormStatus){
          var params=initDataTime(this.searchForm)||{};
          params.page=this.tableData.page||1;
          params.rows=this.tableData.rows||10;
        agentHttp.get('adminApi/admin/mortgage_order_repayment/list', params).then((data)=>{
              this.tableData = data.data.tableData
              this.isSettle =   data.data.isSettleStatusMap ;
              this.isDelay =   data.data.issDelayStatusMap ;
              this.carOrderStatus =   data.data.carOrderStatusMap ; 
              
        })
      }
    },
    debounceSeach(){
      debounce(this.seachData(),1000)
    },
    //重置
    resetSearchForm(formName){
      this.$refs[formName].resetFields();
      this.seachData()
    },
    /*表格操作按钮*/
    //查看
    handleSee(e){
    const value = e.target.innerText ;
    const id  = e.currentTarget.dataset.carorderid
    this.carorderId = id
    this.childCode = value ;    
    this.dialogSendData.dialogFormVisible=true;
    },
    handleEdit(index, row){
      this.dialogSendData.isAdd=true;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    },
    getStatusMap(){
      agentHttp.get('adminApi/admin/car_order_price/get_status_map' ).then((data)=>{
        this.statusMap = data.data;
      })  
    },
    emitButton(obj){    //子组件emit上来的事件，切换显示的子组件
        this.childCode =  obj.value ;
        this.id = obj.id ;
    },
    getDate(time){
      return timestampToTime(time)
    }
   
  }
}